<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            width: 50px;
            height: 50px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
        //获得元素
        var div = document.querySelector('div')
        
        //手指初始坐标
        var startX = 0
        var startY = 0
        //盒子初始坐标
        var x = 0
        var y = 0
        //触摸事件
        div.addEventListener('touchstart', function(e) {
            //获得手指触摸时的初始坐标
            startX = e.targetTouches[0].pageX
            startY = e.targetTouches[0].pageY
            //获得盒子的初始坐标
            x = div.offsetLeft
            y = div.offsetTop
        })

        //手指移动事件
        div.addEventListener('touchmove', function(e) {
            //手指移动距离 = 移动后的坐标 - 初始坐标
            var moveX = e.targetTouches[0].pageX - startX
            var moveY = e.targetTouches[0].pageY - startY
            //盒子移动距离 = 盒子初始坐标 + 手指移动距离
            this.style.left = x + moveX + 'px'
            this.style.top = y + moveY + 'px'
        })
    </script>
</body>
</html>